package my.poemhelper.mb;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import my.poemhelper.vo.PageControl;

public abstract class BaseMB<T> {
	
	protected String loginResult;
	
	protected PageControl<T> pageControl = new PageControl<T>();;

	
	public HttpSession getSession(){
		return (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
	}
	

	public String getLoginResult() {
		return loginResult;
	}

	public void setLoginResult(String loginResult) {
		this.loginResult = loginResult;
	}
	

	
	public PageControl<T> getPageControl() {
		return pageControl;
	}

	public void setPageControl(PageControl<T> pageControl) {
		this.pageControl = pageControl;
	}

	public String preAdd(){
		if(isLogined()){
			return getAddString();
		}else{
			return "login";
		}
	}
	
	protected boolean isLogined(){
		return getSession().getAttribute("user")!=null;
	}
	
	protected abstract String getAddString();
}
